# 设置 Android 环境变量
# 需要管理员权限运行

Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "设置 Android 环境变量" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan

# 设置系统环境变量
Write-Host "`n正在设置系统环境变量..." -ForegroundColor Yellow

try {
    [Environment]::SetEnvironmentVariable("ANDROID_HOME", "C:\platform-tools", [EnvironmentVariableTarget]::Machine)
    Write-Host "✅ ANDROID_HOME = C:\platform-tools" -ForegroundColor Green
    
    [Environment]::SetEnvironmentVariable("ANDROID_SDK_ROOT", "C:\platform-tools", [EnvironmentVariableTarget]::Machine)
    Write-Host "✅ ANDROID_SDK_ROOT = C:\platform-tools" -ForegroundColor Green
} catch {
    Write-Host "❌ 设置系统变量失败（需要管理员权限）" -ForegroundColor Red
    Write-Host "   错误: $_" -ForegroundColor Red
}

# 设置当前会话的环境变量
Write-Host "`n正在设置当前会话的环境变量..." -ForegroundColor Yellow
$env:ANDROID_HOME = "C:\platform-tools"
$env:ANDROID_SDK_ROOT = "C:\platform-tools"
Write-Host "✅ 当前会话已设置" -ForegroundColor Green

# 验证
Write-Host "`n验证设置:" -ForegroundColor Cyan
Write-Host "  ANDROID_HOME = $env:ANDROID_HOME"
Write-Host "  ANDROID_SDK_ROOT = $env:ANDROID_SDK_ROOT"

Write-Host "`n============================================================" -ForegroundColor Cyan
Write-Host "重要提示:" -ForegroundColor Yellow
Write-Host "1. 请关闭并重新启动 Appium Server" -ForegroundColor White
Write-Host "2. 重新启动 Appium 后才能生效" -ForegroundColor White
Write-Host "============================================================" -ForegroundColor Cyan

Read-Host "按回车键退出"

